<?php

namespace app\api\validate;

use think\Validate;

class SetAccountTransferValidate extends Validate
{
    use ValidateModelExist;

    protected $rule = [
        'type' => 'require|requireCallback:checkType',
        'out_account_id' => 'require|exist:setAccount',
        'set_account_id' => 'require|exist:setAccount',
        'account_type_id' => 'require|exist:accountType',
        'business_time' => 'require',
        'amount' => 'require'];

    protected $scene = [
        'mutual'  =>  ['type','set_account_id','out_account_id','amount', 'business_time'],
        'in' => ['type','set_account_id', 'account_type_id','amount', 'business_time'],
        'out' => ['type','set_account_id', 'account_type_id','amount', 'business_time'],
        'adjustment' => ['type','set_account_id', 'amount', 'business_time'],
    ];

    protected function checkType($value, $data)
    {
        return in_array($value, ['mutual', 'in', 'out', 'adjustment'], true);
    }
}
